let echarts = require('echarts/lib/echarts')
// 引入折线图组件
require('echarts/lib/chart/line')
// 引入提示框和title组件
require('echarts/lib/component/tooltip')
require('echarts/lib/component/legend')
require('echarts/lib/component/title')

// 基于准备好的dom，初始化echarts实例
export function initChart (id) {
  let myChart = echarts.init(document.getElementById(id))
  return myChart
}
// chartInstance：图表实例
export function drawLine (chartInstance, xData, yData) {
  // 绘制图表
  // let xAxis = {type: 'category', boundaryGap: false, data: xData}
  chartInstance.setOption({
    color: ['#6067F1', '#0f9d58', '#db4437', '#282baf', '#af9d28'],
    tooltip: {
      trigger: 'axis',
      confine: true
    },
    grid: {
      top: '37px',
      left: '40px',
      right: '40px',
      bottom: '32px',
      containLabel: true
    },
    dataZoom: {
      show: true
    },
    xAxis: {
      data: xData,
      axisLine: {
        show: false
      },
      splitLine: {
        show: false
      },
      boundaryGap: [100, 100]
    },
    yAxis: {
      type: 'value',
      axisLabel: {
        color: '#000000'
      },
      axisLine: {
          lineStyle: {
              color: '#BFBFBF'
          }
      }
    },
    series: [{
      type: 'line',
      data: yData,
      color: ['#6067F1'],
      symbolSize: 1,
      lineStyle: {
        width: 1
      }
    }]
  })
  return chartInstance
}